package cn.itsource.config;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {

@Value("${rocketmq.name-server}")
private String nameServerAddr;

@Value("${rocketmq.producer.group}") //生产组名字
private String group;

// RocketMQ手动拉取消息
@Bean
public DefaultMQPullConsumer pullConsumer(){
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(group+"-consumer");
consumer.setNamesrvAddr(nameServerAddr);
try {
consumer.setMessageModel(MessageModel.CLUSTERING);
consumer.start();
return consumer;
} catch (MQClientException e) {
throw new RuntimeException(e);
}
}
}